package com.supermap.dataservice.project.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.mysql.config.DynamicDataSourceContextHolder;
import com.supermap.dataservice.project.mapper.GetExpertUserListMapper;
import com.supermap.dataservice.project.mapper.entity.Subject;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.product.GetExpertUserListService;


import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年11月04 20:25
 * @email 1301584033@qq.com
 */

@Service
public class GetExpertUserListServiceImpl implements GetExpertUserListService{

    @Resource
    private GetExpertUserListMapper getExpertUserListMapper;

    @Override
    public JSONUtil getExpertdetailsByexperId(String experId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>>
                mapList=getExpertUserListMapper.getExpertdetailsByexperId(experId);
        return mapList!=null?new JSONUtil().setData(mapList):
                new JSONUtil().setCode(100).setIsSuccess(false).setMsg
                        ("error");
    }

    @Override
    public JSONUtil getExepertBysSubjectIdandAreaCode(Integer type,
                                                      Integer areaCode, Integer pageSize, Integer pageNum) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        List<Map<String,Object>> mapList=getExpertUserListMapper.
                getExepertBysSubjectIdandAreaCode
                        (type,areaCode,(pageSize-1)*pageNum,pageNum);
        return  mapList!=null?new JSONUtil().
                setCountSum(
                        getExpertUserListMapper.getExepertBysSubjectIdandAreaCodeCountSum(type,areaCode))
                .setIsSuccess(true).setData(mapList):new JSONUtil
                ().setCode(100).setMsg("查询失败");
    }

    @Override
    public JSONUtil getListSubjectDownExpert(Integer areaCode,Integer pageSize, Integer pageNum,Integer expertNum) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        pageSize =(pageSize-1)*pageNum;
        List<Subject> mapList=getExpertUserListMapper.
                getListSubjectDownExpert
                        (pageSize,pageNum);
            if(mapList!=null && mapList.size()>0){
                for (Subject subject:mapList){
                         subject.setMapList(getExpertUserListMapper.getExepertBysSubjectIdandAreaCode(subject.getSubjectId(),areaCode,0,expertNum));

                }
            }
        return  mapList!=null?new JSONUtil().
                setCountSum(
                        getExpertUserListMapper.getListSubjectDownExpertCountSum())
                .setIsSuccess(true).setData(mapList):new JSONUtil
                ().setCode(100).setMsg("查询失败");
    }
}
